package xhwl.insurance.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.List;

import xhwl.android.common.util.ToastUtil;
import xhwl.insurance.R;
import xhwl.insurance.customView.PlayerWebView;
import xhwl.insurance.http.bean.resp.HospitalListResp;
import xhwl.insurance.http.bean.resp.VideoListResp;
import xhwl.insurance.util.XHLog;
import xhwl.pulltorefresh.adapter.BaseAdapter;
import xhwl.pulltorefresh.adapter.ViewHolder;

/**
 * Created by fuyi on 2017/11/22.
 */

public class HospitalListAdapter extends BaseAdapter<HospitalListResp> {

    private OnItemClickLitener onItemClickLitener;

    public HospitalListAdapter(Context context, List<HospitalListResp> datas) {
        super(context, R.layout.adapter_hospitallist, datas);

    }

    @Override
    public void convert(final ViewHolder holder, final HospitalListResp resp) {
        holder.setText(R.id.hospital_name, resp.getHOS_NAME());
        holder.setText(R.id.hospital_add, resp.getHOS_ADDRESS());
        ImageView fruitImage = (ImageView)holder.getView(R.id.fruit_image);
        Glide.with(context).load(resp.getHOS_PIC()).error(R.drawable.icon_fail).into(fruitImage);
        ImageView levelName = (ImageView)holder.getView(R.id.iv_level_name);//等级
        switch(resp.getLEVEL_NAME()){
            case "三级专科":
          levelName.setImageResource(R.drawable.sanji_zhuanke);
                break;
            case "三级甲等":
                levelName.setImageResource(R.drawable.sanji_jiadeng);
                break;
            case "二级综合":
                levelName.setImageResource(R.drawable.erji_zonghe);
                break;
            case "二级甲等":
                levelName.setImageResource(R.drawable.erji_jiadeng);
                break;
            case "二级乙等":
                levelName.setImageResource(R.drawable.erji_yideng);
                break;
            case "一级甲等":
                levelName.setImageResource(R.drawable.yiji_jiadeng);
                break;
            case "三级综合":
                levelName.setImageResource(R.drawable.sanji_zonghe);
                break;
            case "未定级":
                levelName.setImageResource(R.drawable.weidingji);
                break;
            case "一级综合":
                levelName.setImageResource(R.drawable.yiji_zonghe);
                break;
            case "三级乙等":
                levelName.setImageResource(R.drawable.sanji_yideng);
                break;
            case "二级专科":
                levelName.setImageResource(R.drawable.erji_zhuanke);
                break;
            case "一级乙等":
                levelName.setImageResource(R.drawable.yiji_yideng);
                break;
            default:
                break;
        }

        CardView mCardView = (CardView)holder.getView(R.id.cardview);

        // 如果设置了回调，则设置点击事件
        final int pos = holder.getLayoutPosition();
        if (onItemClickLitener != null) {
            holder.setOnclickListener(R.id.rl_hl_item, new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    onItemClickLitener.onItemClick(pos);
                }
            });

        }
    }

    public interface OnItemClickLitener {
        void onItemClick(int position);
    }

    public void setOnItemClickLitener(OnItemClickLitener onItemClickLitener) {
        this.onItemClickLitener = onItemClickLitener;
    }
}
